/*
 * =====================================================================================
 *
 *       Filename:  datacreate.c
 *
 *    Description:  create database file 
 *
 *        Version:  1.0
 *        Created:  2012年08月24日 14时40分36秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  jianxi sun (jianxi), ycsunjane@gmail.com
 *   Organization:  
 *
 * =====================================================================================
 */

#include <stdio.h>
#include <getopt.h>
#include <stdlib.h>
#include <sys/time.h>

int main(int argc,char *argv[])
{
	if(argc < 3)
	{
		perror("You must specify row num(-r,--row) and column num(-c,--column)\n");
		return -1;
	}

	char c;
	int single_num;
	long long row,column;
	struct timeval tp;
	struct option longopts[]=
	{
		{"row",1,NULL,'r'},
		{"column",1,NULL,'c'},
		{NULL,0,NULL,0},
	};

	while((c=getopt_long(argc,argv,"r:c:",longopts,NULL)) != -1)
	{
		switch (c)
		{
			case 'r':
				row = strtoll(optarg,NULL,0);
				break;
			case 'c':
				column = strtoll(optarg,NULL,0);
				break;
		}
	}

	int ci,ri;
	for(ri=0;ri<row;ri++)
	{
		for(ci=0;ci<column;ci++)
		{
			gettimeofday(&tp,NULL);
			srandom(tp.tv_usec+tp.tv_sec);
			single_num = random()%200;
			if(((single_num <= 122) && (single_num >= 97)) ||
					((single_num <= 90) && (single_num >= 65)) ||
					((single_num <= 57) && (single_num >= 48)))
			{
				printf("%c",single_num);
			}
			else
			{
				ci--;
			}
		}
		printf("\n");
	}
}

